/*
 * Created by 岱青海蓝信息系统(北京)有限公司 on 17-7-13 上午9:22
 * Copyright (c) 2017. All rights reserved.
 */

package com.example.dqhl.jdmetro.adapter.live;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dqhl.jdmetro.R;
import com.example.dqhl.jdmetro.bean.live.LiveDetailComment;
import com.example.dqhl.jdmetro.config.Config;
import com.example.dqhl.jdmetro.view.CircleImageView;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
*description:直播详情 评论Adapter
*autour:guanluocang
*date:17/7/13 09:22
*/
public class LiveCommentAdapater extends RecyclerView.Adapter<LiveCommentAdapater.LiveCommentViewHolder>

    {
        private List<LiveDetailComment.DataBean> mLiveCommentList = new ArrayList<>();
        private Context mContext;
        private LayoutInflater inflater;
        private OnFabulousListener mOnFabulousListener = null;
        private OnDeleteListener mOnDeleteListener = null;

        public LiveCommentAdapater(Context context, List <LiveDetailComment.DataBean> liveCommentList, OnFabulousListener onFabulousListener, OnDeleteListener onDeleteListener)
        {
            this.mContext = context;
            this.mOnDeleteListener = onDeleteListener;
            this.mOnFabulousListener = onFabulousListener;
            this.mLiveCommentList = liveCommentList;
            inflater = LayoutInflater.from(context);
        }

    public void refresh_newHots() {
        notifyDataSetChanged();
    }

    @Override
    public LiveCommentViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LiveCommentViewHolder liveCommentViewHolder = new LiveCommentViewHolder(inflater.inflate(R.layout.layout_consulation_comment, parent, false));
        return liveCommentViewHolder;
    }

    @Override
    public void onBindViewHolder(LiveCommentViewHolder holder, final int position) {
        //点赞量
        holder.tv_fabulousNum.setText(mLiveCommentList.get(position).getComment_like_count() + "");
        //头像
        x.image().bind(holder.iv_photo, Config.pic_base_url + mLiveCommentList.get(position).getPhoto());
        //用户名
        holder.tv_userName.setText(mLiveCommentList.get(position).getName());
        //时间
        holder.tv_addTime.setText(mLiveCommentList.get(position).getComment_add_time());
        //评论内容
        holder.tv_content.setText(mLiveCommentList.get(position).getComment_content());
        //"is_praise":1   //赞的状态：0-未赞，1-已赞
        if (mLiveCommentList.get(position).getIs_comment_like_count() == 1) {
            holder.iv_fabulous.setImageResource(R.drawable.ic_fabulous_pressed);
        } else {
            holder.iv_fabulous.setImageResource(R.drawable.ic_fabulous);
        }
        //点赞
        holder.iv_fabulous.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnFabulousListener.onFabulous(position);
            }
        });
        //删除
        holder.tv_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnDeleteListener.onDelete(position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return mLiveCommentList.size();
    }

    //删除
    public void removeItem(int position) {
        mLiveCommentList.remove(position);
        notifyItemRemoved(position);
        notifyDataSetChanged();
    }

    class LiveCommentViewHolder extends RecyclerView.ViewHolder {
        //点赞数量
        TextView tv_fabulousNum;
        //头像
        CircleImageView iv_photo;
        //用户姓名
        TextView tv_userName;
        //评论时间
        TextView tv_addTime;
        //评论内容
        TextView tv_content;
        //删除
        TextView tv_delete;
        //点赞
        ImageView iv_fabulous;

        public LiveCommentViewHolder(View view) {
            super(view);
            tv_fabulousNum = (TextView) view.findViewById(R.id.tv_fabulousNum);
            tv_userName = (TextView) view.findViewById(R.id.tv_userName);
            tv_addTime = (TextView) view.findViewById(R.id.tv_addTime);
            tv_content = (TextView) view.findViewById(R.id.tv_content);
            tv_delete = (TextView) view.findViewById(R.id.tv_delete);
            iv_photo = (CircleImageView) view.findViewById(R.id.iv_photo);
            iv_fabulous = (ImageView) view.findViewById(R.id.iv_fabulous);

        }
    }

    public static interface OnFabulousListener {
        void onFabulous(int position);
    }

    public static interface OnDeleteListener {
        void onDelete(int position);
    }
}